<!--
 * @Author: gyc
 * @Date: 2020-05-21 11:08:07
 * @LastEditTime: 2020-08-26 09:14:36
 * @Description: Nuxt测试版
--> 
<template>
<div class="user-aside">
    <Menu :theme="theme" width="100%" :active-name="activeName" :open-names="openNames" :accordion="true">
        <Submenu name="1">
            <template slot="title">
                <Icon type="ios-paper" />个人中心
            </template>
            <MenuItem name="1-1" to="/user/userInfo">我的信息</MenuItem>
            <MenuItem name="1-2" to="/user/userAvatar">更换头像</MenuItem>
            <MenuItem name="1-3" to="/user/userSpace">个人空间</MenuItem>
        </Submenu>
        <Submenu name="2">
            <template slot="title">
                <Icon type="ios-people" />分享专区
            </template>
            <MenuItem name="2-1" to="/pubShare">我要分享</MenuItem>
            <MenuItem name="2-2" to="/writeArt">编写文章</MenuItem>
        </Submenu>
        <Submenu name="3">
            <template slot="title">
                <Icon type="md-settings" />系统操作
            </template>
            <MenuItem name="3-1" to="/user/userAccount">账号状态</MenuItem>
            <MenuItem name="3-2" to="resetPwd">修改密码</MenuItem>
            <MenuItem name="3-3">系统设置</MenuItem>
        </Submenu>
        <Submenu name="4">
            <template slot="title">
                <Icon type="md-settings" />内容管理
            </template>
            <MenuItem name="4-1" to="/user/shareManage">分享管理</MenuItem>
            <MenuItem name="4-2" to="/user/articleManage">文章管理</MenuItem>
        </Submenu>
        <Submenu name="5" v-if="admin==1">
            <template slot="title">
                <Icon type="md-settings" />管理网站
            </template>
            <MenuItem name="5-1" to="/user/userManage">账号管理</MenuItem>
            <MenuItem name="5-2" to="/user/articleManage">内容管理</MenuItem>
            <MenuItem name="5-3">平台数据</MenuItem>
        </Submenu>
    </Menu>
</div>
</template>

<script>
export default {
    name: "userAside",
    props: ["admin"],
    data() {
        return {
            asideItem: [{
                    name: "个人信息",
                    to: "/user",
                },
                {
                    name: "我的动态",
                    to: "/user",
                },
            ],
            theme: "light",
            isAdmin: "",
            activeName: "",
            openNames: [],
        };
    },
    beforeMount() {
        const path = this.$router.history.current.path;
        console.log(path, "111");
        switch (path) {
            case "/user/userInfo": {
                this.activeName = "1-1";
                this.openNames = ["1"];
                return;
            }
            case "/user/userAvatar": {
                this.activeName = "1-2";
                this.openNames = ["1"];
                return;
            }
        }
    },
    methods: {
        //退出登录
        loginOut() {
            alert(1);
            localStorage.removeItem("loginUser");
            this.$router.push("/");
            let timer = setTimeout(() => {
                window.location.reload();
                clearTimeout(timer);
            }, 100);
        },
        selectItem(e) {
            // $(".user-aside-item").removeClass("select-item");
            $("#" + e.target.id).addClass("select-item");
        },
    },
    mounted() {},
};
</script>

<style lang="scss" scoped>
a {
    color: #515a6e;
}

.user-aside {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    background-color: white;

    // border-top: 1px solid #dcdee2;
    // padding: 10px;
    &::after {
        content: "";
        position: absolute;
        height: 100%;
        width: 1px;
        background-color: white;
        right: 0;
        top: 0;
        z-index: 900;
    }

    .user-aside-box {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        height: 100px;
        margin-bottom: 10px;
        border-right: 4px;
        box-shadow: 0px 0px 4px #aaa;

        p {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 80%;
            height: 30px;
            color: black;
            font-weight: 600;
            border-bottom: 1px solid #ccc;
        }

        .user-aside-box-main {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 80%;
            height: 40px;
        }
    }

    .user-aside-item {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 40px;
        cursor: pointer;
        transition: all 0.4s ease-in-out;
    }

    .user-share {
        width: 80%;
        display: flex;
        justify-content: space-between;
    }

    .login-out {
        width: 100%;
        cursor: pointer;
        height: 25px;
        line-height: 25px;
        text-align: center;
        background-color: rgb(253, 98, 98);
        color: white;
        border-radius: 4px;
        margin-bottom: 10px;

        &:hover {
            background-color: rgba(255, 0, 0, 1);
        }
    }
}

.select-item {
    background-color: rgba(187, 187, 187, 0.4);
}
</style>
